import 'package:flutter/material.dart';
import 'package:flutter_base/config/app_color.dart';
import 'package:flutter_base/pages/test_questions/test_questions_logic.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class ChoiceQuestionWidget extends StatelessWidget {
  const ChoiceQuestionWidget({super.key, required this.logic});

  final TestQuestionsLogic logic;

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: (logic.currentQuestion?.options ?? []).map((option) {
          final isSelected = logic.isOptionMultiSelected(option.id!);
          // final isSelected = logic.isOptionMultiSelected(option.id!);

          // return GestureDetector(
          // onTap: () => logic.toggleAnswer(option.id!),
          return GestureDetector(
            onTap: () {
              if (logic.currentQuestion?.type == 1) {
                logic.selectAnswer(option.id!);
              } else {
                logic.toggleAnswer(option.id!);
              }
            },
            child: Container(
              decoration: BoxDecoration(
                color: isSelected ? AppColor.primary : Colors.white,
                borderRadius: BorderRadius.circular(12.w),
                boxShadow: [
                  BoxShadow(
                    color: AppColor.primary.withOpacity(0.12),
                    offset: Offset(0, 4.w),
                    blurRadius: 11.w,
                  ),
                ],
              ),
              padding: EdgeInsets.all(12.w),
              child: Row(
                children: [
                  Text(
                    optionLetter(
                        (logic.currentQuestion?.options ?? []).indexOf(option)),
                    style: TextStyle(
                      fontSize: 16.sp,
                      fontWeight: FontWeight.w900,
                      color: isSelected ? Colors.white : AppColor.color0C0A09,
                    ),
                  ),
                  SizedBox(width: 12.w),
                  Expanded(
                    child: Text(
                      option.content ?? '',
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: isSelected ? Colors.white : AppColor.color7F909F,
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ).marginOnly(bottom: 24.w);
        }).toList(),
      ),
    );
  }

  String optionLetter(int id) {
    // 这里简化处理，实际应用中可能需要根据选项顺序来决定字母
    final letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
    final index = id % letters.length;
    return letters[index];
  }
}
